package com.lg.algorithm.ms;

/**
 * string 两个大数求和
 */
public class JD {
    public static void main(String[] args) {
        String num1 = "123";
        String num2 = "999";
        System.out.println(bigAdder(num1,num2));
    }

    private static String bigAdder(String num1,String num2) {
        char[] chars1 = num1.toCharArray();
        char[] chars2 = num2.toCharArray();
        int index1 = chars1.length - 1;
        int index2 = chars2.length - 1;
        String res = "";
        int nextNum = 0;
        int count = 0;
        while (index1>-1 || index2>-1) {
            if (index1 < 0) {
                count = Integer.parseInt(String.valueOf(chars1[index2])) + nextNum;
            } else if (index2 < 0) {
                count = Integer.parseInt(String.valueOf(chars1[index1])) + nextNum;
            } else {
                count = Integer.parseInt(String.valueOf(chars1[index1])) + Integer.parseInt(String.valueOf(chars2[index2]))+nextNum;
            }
            nextNum = count / 10;
            res = (count % 10) + res;
            index1--;
            index2--;
        }
        if (nextNum != 0) {
            res = nextNum + res;
        }
        return res;
    }
}
